#!/usr/bin/with-contenv bashio
# vim: ft=bash
# shellcheck shell=bash
# ==============================================================================
# Send zwave_js discovery information to Home Assistant
# ==============================================================================
declare ha_config

# Prepare discovery payload
ha_config=$(\
    bashio::var.json \
        host "$(hostname)" \
        port "^3000" \
)

if bashio::discovery "zwave_js" "${ha_config}" > /dev/null; then
    bashio::log.info "Successfully send discovery information to Home Assistant."
else
    bashio::log.error "Discovery message to Home Assistant failed!"
fi
